package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.model.SystemNotification;
import com.lonty.intelligence.service.SystemNotificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/5/28 10:17
 * @Version 1.0
 */
@RestController
@RequestMapping("app/systemNotification")
@Validated
@Api(tags = "系统通知接口", produces = "application/json")
public class SystemNotificationController {

    @Resource
    private SystemNotificationService systemNotificationService;

    @ApiOperation(value = "保存系统通知", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "内容",dataType = "string", paramType = "query", required = true)
    })
    @PostMapping("saveSystemNotification")
    public Result saveSystemNotification(String content){
        if(systemNotificationService.saveSystemNotification(content)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "获取用户所有通知", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userInfoId", value = "用户ID",dataType = "string", paramType = "query", required = true)
    })
    @GetMapping("getAllSystemNotificationList")
    public Result getAllSystemNotificationList(String userInfoId){
        return Result.builder()
                .data(systemNotificationService.getAllSystemNotificationList(userInfoId))
                .build();
    }

    @ApiOperation(value = "统计用户未读", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userInfoId", value = "用户ID",dataType = "string", paramType = "query", required = true)
    })
    @GetMapping("countUnread")
    public Result countUnread(String userInfoId){
        return Result.builder()
                .data(systemNotificationService.countUnread(userInfoId))
                .build();
    }

    @ApiOperation(value = "获取通知详情", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "通知ID",dataType = "string", paramType = "query", required = true),
            @ApiImplicitParam(name = "userInfoId", value = "用户ID",dataType = "string", paramType = "query", required = true)
    })
    @GetMapping("getSystemNotification")
    public Result getSystemNotification(String id, String userInfoId){
        SystemNotification systemNotification = systemNotificationService.getSystemNotification(id, userInfoId);
        if(systemNotification != null){
            return Result.builder().data(systemNotification).build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

}
